SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


Alter  trigger tfb_fixastmodify_bi   on dbo.tfb_fixastmodify 
instead of insert 
as   
begin   
  if @@rowcount<>1 return
  set nocount on
  declare @new_modtypeid int;
  declare @new_voucherid int;
  declare @old_fixedassetid integer;
  declare @filid integer;

  select @new_modtypeid = modtypeid,@old_fixedassetid=fixedassetid
  from inserted;

  select @filid=filid from tfb_fixedassets
    where fixedassetid=@old_fixedassetid;


  execute p_voucherinit null,null,null,null,@filid;   
  if ((@new_modtypeid<>1) and (@new_modtypeid<>6) and (@new_modtypeid<>9) and  (@new_modtypeid<>10))   
      set @new_voucherid = -1;  
  else
      set @new_voucherid = null;  
  insert  into tfb_fixastmodify 
  select
  faadjid,
  modtypeid,
  fixedassetid,
  create_by,
  filid,
  oldstatusid,
  newstatusid,
  olddeprmethodid,
  newdeprmethodid,
  @new_voucherid,
  code,
  changedate,
  changereason,
  workunit,
  oldrawamt,
  newrawamt,
  oldplanusemonth,
  newplanusemonth,
  oldsumdepramt,
  newsumdepramt,
  oldplanworkvalue,
  newplanworkvalue,
  oldlocation,
  newlocation,
  oldremainrate,
  newremainrate,
  oldremainamt,
  newremainamt,
  newsumusedmonth,
  newsumworkedvalue,
  oldastsubid,
  newastsubid,
  oldprice,
  newprice,
  oldquantity,
  newquantity,
  subjectid,
  newdepsubid,
  olddepsubid
  from inserted;
end




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

